package com.tencent.wxcloudrun.manager;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import com.tencent.wxcloudrun.domain.TQuestion;
import com.tencent.wxcloudrun.dto.QuestionListResDTO;
import com.tencent.wxcloudrun.service.TQuestionService;
import com.tencent.wxcloudrun.vo.request.sys.QuestionListReqVo;
import com.tencent.wxcloudrun.vo.request.sys.SysConfigListReqVo;
import com.tencent.wxcloudrun.vo.request.sys.SysFillListReqVo;
import com.tencent.wxcloudrun.vo.response.sys.QuestionListResVo;
import com.tencent.wxcloudrun.vo.response.sys.SysConfigListResVo;
import com.tencent.wxcloudrun.vo.response.sys.SysFillListResVo;

import lombok.extern.slf4j.Slf4j;

/**
 * @Author ZhaoZiYin
 * @Date 2025/4/22
 * @Description 系统管理端
 */
@Service
@Slf4j
public class SysManager {

    @Resource
    private TQuestionService questionService;

    /**
     * @Author: ZhaoZiYin
     * @Date: 2025/4/22
     * @Params: [reqVo]
     * @Return: SysFillListResVo
     * @Description: 查询系统预填信息
     */
    public SysFillListResVo listSysFill(SysFillListReqVo reqVo) {
        return null;
    }

    /**
     * @Author: ZhaoZiYin
     * @Date: 2025/4/22
     * @Params: [reqVo]
     * @Return: SysConfigListResVo
     * @Description: 查询系统配置信息
     */
    public SysConfigListResVo listSysConfig(SysConfigListReqVo reqVo) {
        return null;
    }

    /**
     * @Author: ZhaoZiYin
     * @Date: 2025/6/3
     * @Params: [reqVo]
     * @Return: QuestionListResVo
     * @Description: 查询问题信息
     */
    public QuestionListResVo listQuestion(QuestionListReqVo reqVo) {
        QuestionListResVo resVo = new QuestionListResVo();
        List<TQuestion> questionList = questionService.list();
        if (!CollectionUtils.isEmpty(questionList)) {
            List<QuestionListResDTO> resDTOList = new ArrayList<>();
            Map<String, List<TQuestion>> questionMap = questionList.stream()
                .collect(Collectors.groupingBy(TQuestion::getType, LinkedHashMap::new, Collectors.toList()));
            for (String type : questionMap.keySet()) {
                QuestionListResDTO resDTO = new QuestionListResDTO();
                List<TQuestion> questions = questionMap.get(type);
                resDTO.setType(type);
                resDTO.setTypeIcon(questions.get(0).getTypeIcon());
                resDTO.setQuestionList(questions);
                resDTOList.add(resDTO);
            }
            resVo.setQuestionList(resDTOList);
        }
        return resVo;
    }

}
